<?php
function litimgurls($imgid=0)
{
    global $lit_imglist,$dsql;
    //获取附加表
    $row = $dsql->GetOne("SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c 
                                                            ON a.channel=c.id where a.id='$imgid'");
    $addtable = trim($row['addtable']);
    
    //获取图片附加表imgurls字段内容进行处理
    $row = $dsql->GetOne("Select imgurls From `$addtable` where aid='$imgid'");
    
    //调用inc_channel_unit.php中ChannelUnit类
    $ChannelUnit = new ChannelUnit(2,$imgid);
    
    //调用ChannelUnit类中GetlitImgLinks方法处理缩略图
    $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
    
    //返回结果
    return $lit_imglist;
}

function typid($val){
	$a='<div class="mainCont selected">';
	$b='<div class="mainCont">';
	if($val==13)
	{
		return $a;
	}else{
		return $b;
	}


}

/*
*获取字符串的第一个图片地址
*/
function getbodyfirstpic($str_img){
    preg_match_all("/<img.*\>/isU",$str_img,$ereg);//正则表达式把图片的整个都获取出来了 
    $img=$ereg[0][0];//图片 
    $p="#src=('|\")(.*)('|\")#isU";//正则表达式
    preg_match_all ($p, $img, $img1); 
    $img_path =$img1[2][0];//获取第一张图片路径  
return $img; //返回整个图片
}
/**
*  文章内容提取第一张图片
*
* @access    public
* @param     string  $id文档id
* @param     string  $addField字段名
* @return    string
*/
if(!function_exists('getBodyonepic'))
{
function getBodyonepic($id, $addField='body')
{
global $dsql;
$row = $dsql->GetOne("SELECT a.litpic,c.addtable FROM dede_archives AS a LEFT JOIN dede_channeltype AS c ON a.channel=c.id where a.id='$id'");
$addtable = trim($row['addtable']);
if($row['litpic'] == '-' || $row['litpic'] == '')
{
$litpic = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
}
$row = $dsql->GetOne("SELECT $addField FROM `$addtable` WHERE aid=$id");
$body = $row["$addField"];
preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/",$body,$matches);
$imgsrc_arr = array_unique($matches[3]);
$result = $imgsrc_arr[0] ? $imgsrc_arr[0] : $litpic;
return $result;
}
}
